package com.houzehui.product.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.houzehui.product.dto.SpuQueryDto;
import com.houzehui.product.entity.*;
import com.houzehui.product.mapper.SkuMapper;
import com.houzehui.product.mapper.SpuMapper;
import com.houzehui.product.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.houzehui.product.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * <p>
 * spu表，该表描述的是一个抽象性的商品，比如 iphone8 服务实现类
 * </p>
 *
 * @author houzehui
 * @since 2022-04-27
 */
@Service
public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements ISpuService {

    @Autowired
    SkuMapper skuMapper;

//    @Autowired
//    ISkuService iSkuService;
//
//    @Autowired
//    ISpuDetailService iSpuDetailService;
//
//    @Autowired
//    ICategoryService iCategoryService;
//
//    @Autowired
//    ICategoryBrandService iCategoryBrandService;
//
//    @Autowired
//    IBrandService iBrandService;


    @Override
    public PageInfo<SpuListVo> selectSpuList(SpuQueryDto spuQueryDto, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        List<SpuListVo> spuListVos = getBaseMapper().selectSpuList(spuQueryDto);
        spuListVos.forEach(s->{
            QueryWrapper<Sku> wrapper = new QueryWrapper<>();
            wrapper.eq("spu_id",s.getId());
            List<Sku> skus = skuMapper.selectList(wrapper);
            for(int i=0;i<1;i++){
                s.setSkuId(skus.get(i).getId());
            }
        });



        return new PageInfo<>(spuListVos);
    }



}
